var EquipSkillLayer = cc.Layer.extend({
    isMouseDown:false,

    ccbNode:null,

    rectsInited:false,

    itemNameLabel:null,
    itemInfoLabel:null,
    itemAttrLabel:null,
    skillActiveBtn:null,
    floatItem:null,
    init:function () {

        //////////////////////////////
        // 1. super init first
        this._super();
        this.setTouchEnabled(true);
        /////////////////////////////
        // 2. add a menu item with "X" image, which is clicked to quit the program
        //    you may modify it.
        // ask director the window size
        var size = cc.Director.getInstance().getVisibleSize();
        var size2 =  cc.Director.getInstance().getWinSize();

        cc.BuilderReader.setResourcePath("ccb/");

        //load ccbi scene
        this.ccbNode = cc.BuilderReader.load("ccb/EquipSkillScene.ccbi", this);
        //this.ccbNode.animationManager.setCompletedAnimationCallback(this, this.animationCompleteCallback);

        //init scene
        //read record
        /*
            back 2
            confirm 3
            container 30
                equip tab 1
                skill tab 2
                bag container 3
                    box 1-20
                        weapon 1
                        select border 2
                skill container 4
                    skill bg 1
                        skill 1-8
                            skill_star  1
                            select border 2
                    star_num 2
            role container 20
                role 1
                lv label 2
                name label 3
                head bg 11
                    item 1
                armor bg 12
                    item 1
                boots bg 13
                    item 1
                ring bg1 14
                    item 1
                weapon bg 15
                    item 1
                ring bg2 16
                    item 1
            intro 10
                name 10  both for item and skill
                intro 11  both for item and skill
                attribute 12  only for item
                active_btn 13 for skill panel
            dragIcon 100
        */

        // 默认进入显示背包页 
        this.ccbNode.getChildByTag(30).getChildByTag(3).setVisible(true);
        this.ccbNode.getChildByTag(30).getChildByTag(4).setVisible(false);
        var activeTexture = cc.TextureCache.getInstance().addImage("ccb/ccbResources/tab_active.png");
        var unactiveTexture = cc.TextureCache.getInstance().addImage("ccb/ccbResources/tab_unactive.png");
        this.ccbNode.getChildByTag(30).getChildByTag(1).setTexture(activeTexture);
        this.ccbNode.getChildByTag(30).getChildByTag(2).setTexture(unactiveTexture);

        // 物品信息
        this.itemNameLabel=this.ccbNode.getChildByTag(10).getChildByTag(10);
        this.itemInfoLabel=this.ccbNode.getChildByTag(10).getChildByTag(11);
        this.itemAttrLabel=this.ccbNode.getChildByTag(10).getChildByTag(12);  
        this.skillActiveBtn=this.ccbNode.getChildByTag(10).getChildByTag(13);
        this.itemNameLabel.setVisible(false);
        this.itemInfoLabel.setVisible(false);     
        this.itemAttrLabel.setVisible(false);
        this.skillActiveBtn.setVisible(false);

        // 默认intro全为空
        this.ccbNode.getChildByTag(10).getChildByTag(10).setString("");
        this.ccbNode.getChildByTag(10).getChildByTag(11).setString("");
        this.ccbNode.getChildByTag(10).getChildByTag(12).setString("");

        // 隐藏拖曳图标
        this.floatItem=this.ccbNode.getChildByTag(100);
        this.floatItem.setVisible(false);

        // 初始化背包页面
        this.refreshBag();

        // 设置初始人物 及技能 及装备情况
        this.switchRole(Game.gameRecord[Game.currRecord]["character"][0][this.currRoleIndex]);

        if(this.ccbNode != null) {
            this.addChild(this.ccbNode);
        }

        this.initTouchPositions();

        // test
    },
    animationCompleteCallback: function(){
        console.log("animation end...");
    },

    equipTabRect:null,
    skillTabRect:null,
    backBtnRect:null,
    confirmBtnRect:null,
    roleWeaponRect:null,
    roleHeadRect:null,
    roleArmorRect:null,
    roleBootsRect:null,
    roleHandRect:null,
    roleRingRect:null,
    roleRoleRect:null,
    equipSkillPanelRect:null,
    rolePanelRect:null,
    introPanelRect:null,
    skillActiveBtnRect:null,
    equipBagRect:[],
    skillRect:[],

    currTab:0, //0:bag 1:skill
    currRoleIndex:1,
    touchedItemType:0, // 1-6 点击的物品种类
    touchedItemId:0, // 1-5 点击的物品id
    touchedItemIndex:0, // 1-20 or 1-10 点击的物品index
    touchedFromBagOrRole:0, // 1 bag 2 roleEquip
    touchedSkillSelectedId:0, // 选中的技能
    initTouchPositions: function(){
        console.log("init Touch Positions");
        if(!this.rectsInited){
            this.backBtnRect=this.ccbNode.getChildByTag(2).getBoundingBox();
            this.confirmBtnRect=this.ccbNode.getChildByTag(3).getBoundingBox();

            this.equipTabRect=this.ccbNode.getChildByTag(30).getChildByTag(1).getBoundingBox();
            this.skillTabRect=this.ccbNode.getChildByTag(30).getChildByTag(2).getBoundingBox();

            this.roleWeaponRect=this.ccbNode.getChildByTag(20).getChildByTag(11).getBoundingBox();
            this.roleHeadRect=this.ccbNode.getChildByTag(20).getChildByTag(12).getBoundingBox();
            this.roleArmorRect=this.ccbNode.getChildByTag(20).getChildByTag(13).getBoundingBox();
            this.roleBootsRect=this.ccbNode.getChildByTag(20).getChildByTag(14).getBoundingBox();
            this.roleHandRect=this.ccbNode.getChildByTag(20).getChildByTag(15).getBoundingBox();
            this.roleRingRect=this.ccbNode.getChildByTag(20).getChildByTag(16).getBoundingBox();
            this.roleRoleRect=this.ccbNode.getChildByTag(20).getChildByTag(1).getBoundingBox();

            this.equipSkillPanelRect=this.ccbNode.getChildByTag(30).getBoundingBox();
            this.rolePanelRect=this.ccbNode.getChildByTag(20).getBoundingBox();

            for(var i=1;i<=20;i++){
                this.equipBagRect[i]=this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getBoundingBox();
            }
            for(var i=1;i<=8;i++){
                this.skillRect[i]=this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getBoundingBox();
            }

            this.introPanelRect=this.ccbNode.getChildByTag(10).getBoundingBox();
            this.skillActiveBtnRect=this.ccbNode.getChildByTag(10).getChildByTag(13).getBoundingBox();

            this.rectsInited=true;
        }
    },
    onTouchesEnded: function(pTouch, pEvent){
        var touchPoint=pTouch[0].getLocation();
        // console.log("touch end",touchPoint);
        if(cc.rectContainsPoint(this.backBtnRect, touchPoint)){
            console.log("Touch BACK");
            Game.currScene=new MainStageScene();
            cc.Director.getInstance().replaceScene(cc.TransitionFade.create(0.5, Game.currScene, cc.black()));
            return true;
        }
        // touch on confirm
        if(cc.rectContainsPoint(this.confirmBtnRect, touchPoint)){
            console.log("Touch Confirm");
            Game.currScene=new MainStageScene();
            cc.Director.getInstance().replaceScene(cc.TransitionFade.create(0.5, Game.currScene, cc.black()));
            return true;
        }

        // 点击在Tab页
        var pointAtTab=this.ccbNode.getChildByTag(30).convertToNodeSpace(touchPoint);
        if(cc.rectContainsPoint(this.equipTabRect, pointAtTab)){
            // 点击在equip tab
            this.switchToBagTab();
            return true;
        }
        if(cc.rectContainsPoint(this.skillTabRect, pointAtTab)){
            // 点击在skill tab
            this.switchToSkillTab();
            return true;
        }

        this.floatItem.setVisible(false);

        //人物面板
        if(cc.rectContainsPoint(this.rolePanelRect, touchPoint)){
            var pointAtRole=this.ccbNode.getChildByTag(20).convertToNodeSpace(touchPoint);
            var currRoleId=Game.gameRecord[Game.currRecord]["character"][0][this.currRoleIndex];
            // 点击在人物
            if(cc.rectContainsPoint(this.roleRoleRect, pointAtRole)){
                var rolesInfo=Game.gameRecord[Game.currRecord]["character"][0];
                if(this.currRoleIndex==4){
                    // 切换到第一个
                    this.currRoleIndex=1;
                }else if(rolesInfo[this.currRoleIndex+1]==0 || typeof rolesInfo[this.currRoleIndex+1] == "undefined"){
                    this.currRoleIndex=1;
                }else{
                    this.currRoleIndex+=1;
                }
                this.switchRole(rolesInfo[this.currRoleIndex]);
            }
            // 如果要替换装备
            if(this.touchedFromBagOrRole==1 && this.touchedItemId>0 && this.touchedItemType>0){
                // 更换装备
                Game.roleEquipItem(Game.currRecord, currRoleId, this.touchedItemType, this.touchedItemId, this.touchedItemIndex);
                this.refreshBag();
                this.switchRole(currRoleId);
            }
            this.touchedItemType=0;
            this.touchedItemId=0;
            this.touchedItemIndex=0;
            this.touchedFromBagOrRole=0;
            return true;
        }

        //背包区域
        if(cc.rectContainsPoint(this.equipSkillPanelRect, touchPoint)){
            var currRoleId=Game.gameRecord[Game.currRecord]["character"][0][this.currRoleIndex];
            if(this.touchedFromBagOrRole==2 && this.touchedItemId>0 && this.touchedItemType>0){
                // 更换装备
                Game.roleUnequipItem(Game.currRecord, currRoleId , this.touchedItemType);
                this.refreshBag();
                this.switchRole(currRoleId);
            }
            this.touchedItemType=0;
            this.touchedItemId=0;
            this.touchedItemIndex=0;
            this.touchedFromBagOrRole=0;
            return true;
        }
    },
    onTouchesBegan: function(pTouch, pEvent){
        var touchPoint=pTouch[0].getLocation();

        // 点在物品栏 并处于背包物品状态
        if(this.currTab==0 && cc.rectContainsPoint(this.equipSkillPanelRect, touchPoint)){
            var touchAtBag=this.ccbNode.getChildByTag(30).getChildByTag(3).convertToNodeSpace(touchPoint);
            for(var i=1;i<=20;i++){
                if(cc.rectContainsPoint(this.equipBagRect[i], touchAtBag)){
                    console.log("Touch begin bag item "+i);
                    this.touchedItemType=Game.gameRecord[Game.currRecord]["have_equip"][i][0];
                    this.touchedItemId=Game.gameRecord[Game.currRecord]["have_equip"][i][1];
                    this.touchedItemIndex=i;
                    this.touchedFromBagOrRole=1;
                    this.setEquipInfo(this.touchedItemType,this.touchedItemId);
                    this.showItemSelectBorder(1,this.touchedItemIndex);
                    var equipImgPath = this.getEquipImgPathByTypeAndId(this.touchedItemType,this.touchedItemId);
                    var texture = cc.TextureCache.getInstance().addImage(equipImgPath);
                    this.floatItem.setTexture(texture);
                    return true;
                }
            }
        }
        // 点在物品技能 并处于技能状态
        if(this.currTab==1 && cc.rectContainsPoint(this.equipSkillPanelRect, touchPoint)){
            var touchAtSkill=this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).convertToNodeSpace(touchPoint);
            for(var i=1;i<=8;i++){
                if(cc.rectContainsPoint(this.skillRect[i], touchAtSkill)){
                    var currRoleId=Game.gameRecord[Game.currRecord]["character"][0][this.currRoleIndex];
                    console.log("Touch begin skill "+i);
                    // 点击技能选择/加点
                    if(this.touchedSkillSelectedId==i){
                        // 是否已经选中了该技能 加点
                        Game.addSkillPoint(Game.currRecord, currRoleId, i);
                        this.refreshSkill(currRoleId);
                    }else{
                        // 选中
                        // 显示技能信息 设置激活按钮显示状态
                        var skillId=Game.characterBaseAttrInfo[currRoleId]["skill"][i];
                        var skillIsActive=Game.gameRecord[Game.currRecord]["character_skill"][currRoleId][i][1];
                        this.setSkillInfo(skillId, skillIsActive);
                        this.showSkillSelectBorder(i);
                        this.touchedSkillSelectedId=i;
                    }
                    return true;
                }
            }
        }

        // 技能界面 点击在激活按钮上
        if(this.currTab==1 && this.touchedSkillSelectedId>0 && cc.rectContainsPoint(this.introPanelRect, touchPoint)){
            var touchAtIntroPanel=this.ccbNode.getChildByTag(10).convertToNodeSpace(touchPoint);
            if(cc.rectContainsPoint(this.skillActiveBtnRect, touchAtIntroPanel)){
                console.log("Touch begin skill active");
                var currRoleId=Game.gameRecord[Game.currRecord]["character"][0][this.currRoleIndex];
                // 点击技能激活
                var skillIsActive=Game.gameRecord[Game.currRecord]["character_skill"][currRoleId][this.touchedSkillSelectedId][1];
                if(skillIsActive==1){
                    var successFlag=Game.disableSkill(Game.currRecord, currRoleId, this.touchedSkillSelectedId);
                    this.refreshSkill(currRoleId);
                    if(successFlag){
                        var skillId=Game.characterBaseAttrInfo[currRoleId]["skill"][this.touchedSkillSelectedId];
                        this.setSkillInfo(skillId, 0);
                    }
                }else{
                    var successFlag=Game.enableSkill(Game.currRecord, currRoleId, this.touchedSkillSelectedId);
                    this.refreshSkill(currRoleId);
                    if(successFlag){
                        var skillId=Game.characterBaseAttrInfo[currRoleId]["skill"][this.touchedSkillSelectedId];
                        this.setSkillInfo(skillId, 1);
                    }
                }
                return true;
            }
        }

        // 背包物品状态 点击在人物面板
        if(this.currTab==0 && cc.rectContainsPoint(this.rolePanelRect, touchPoint)){
            var touchAtRolePanel=this.ccbNode.getChildByTag(20).convertToNodeSpace(touchPoint);
            var currRoleId=Game.gameRecord[Game.currRecord]["character"][0][this.currRoleIndex];
            if(cc.rectContainsPoint(this.roleWeaponRect, touchAtRolePanel)){
                console.log("Touch begin weapon");
                this.touchedItemType=1;
                this.touchedItemId=Game.gameRecord[Game.currRecord]["character"][currRoleId][1];
                this.touchedItemIndex=1;
                this.touchedFromBagOrRole=2;
                this.setEquipInfo(this.touchedItemType,this.touchedItemId);
                var equipImgPath = this.getEquipImgPathByTypeAndId(this.touchedItemType,this.touchedItemId);
                var texture = cc.TextureCache.getInstance().addImage(equipImgPath);
                this.floatItem.setTexture(texture);
                return true;
            }else if(cc.rectContainsPoint(this.roleHeadRect, touchAtRolePanel)){
                console.log("Touch begin head");
                this.touchedItemType=2;
                this.touchedItemId=Game.gameRecord[Game.currRecord]["character"][currRoleId][2];
                this.touchedItemIndex=2;
                this.touchedFromBagOrRole=2;
                this.setEquipInfo(this.touchedItemType,this.touchedItemId);
                var equipImgPath = this.getEquipImgPathByTypeAndId(this.touchedItemType,this.touchedItemId);
                var texture = cc.TextureCache.getInstance().addImage(equipImgPath);
                this.floatItem.setTexture(texture);
                return true;
            }else if(cc.rectContainsPoint(this.roleArmorRect, touchAtRolePanel)){
                console.log("Touch begin armor");
                this.touchedItemType=3;
                this.touchedItemId=Game.gameRecord[Game.currRecord]["character"][currRoleId][3];
                this.touchedItemIndex=3;
                this.touchedFromBagOrRole=2;
                this.setEquipInfo(this.touchedItemType,this.touchedItemId);
                var equipImgPath = this.getEquipImgPathByTypeAndId(this.touchedItemType,this.touchedItemId);
                var texture = cc.TextureCache.getInstance().addImage(equipImgPath);
                this.floatItem.setTexture(texture);
                return true;
            }else if(cc.rectContainsPoint(this.roleBootsRect, touchAtRolePanel)){
                console.log("Touch begin boots");
                this.touchedItemType=4;
                this.touchedItemId=Game.gameRecord[Game.currRecord]["character"][currRoleId][4];
                this.touchedItemIndex=4;
                this.touchedFromBagOrRole=2;
                this.setEquipInfo(this.touchedItemType,this.touchedItemId);
                var equipImgPath = this.getEquipImgPathByTypeAndId(this.touchedItemType,this.touchedItemId);
                var texture = cc.TextureCache.getInstance().addImage(equipImgPath);
                this.floatItem.setTexture(texture);
                return true;
            }else if(cc.rectContainsPoint(this.roleHandRect, touchAtRolePanel)){
                console.log("Touch begin hand");
                this.touchedItemType=5;
                this.touchedItemId=Game.gameRecord[Game.currRecord]["character"][currRoleId][5];
                this.touchedItemIndex=5;
                this.touchedFromBagOrRole=2;
                this.setEquipInfo(this.touchedItemType,this.touchedItemId);
                var equipImgPath = this.getEquipImgPathByTypeAndId(this.touchedItemType,this.touchedItemId);
                var texture = cc.TextureCache.getInstance().addImage(equipImgPath);
                this.floatItem.setTexture(texture);
                return true;
            }else if(cc.rectContainsPoint(this.roleRingRect, touchAtRolePanel)){
                console.log("Touch begin ring");
                this.touchedItemType=6;
                this.touchedItemId=Game.gameRecord[Game.currRecord]["character"][currRoleId][6];
                this.touchedItemIndex=6;
                this.touchedFromBagOrRole=2;
                this.setEquipInfo(this.touchedItemType,this.touchedItemId);
                var equipImgPath = this.getEquipImgPathByTypeAndId(this.touchedItemType,this.touchedItemId);
                var texture = cc.TextureCache.getInstance().addImage(equipImgPath);
                this.floatItem.setTexture(texture);
                return true;
            }
        }

        this.cancelSelectBorder();
        this.clearEquipInfo();
    },
    onTouchesMoved: function(pTouch, pEvent){
        var touchPoint=pTouch[0].getLocation();

        if(this.touchedItemId==0 && this.touchedItemType==0){

        }else{
            this.floatItem.setVisible(true);
            this.floatItem.setPosition(touchPoint);
        }
    },

    refreshBag: function(){
        for(var i=1;i<=20;i++){
            var equipItem = Game.gameRecord[Game.currRecord]["have_equip"][i];
            if(equipItem[0]==0){
                this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(1).setVisible(false);
            }else{
                var imgPath = this.getEquipImgPathByTypeAndId(equipItem[0],equipItem[1]);
                var texture = cc.TextureCache.getInstance().addImage(imgPath);
                this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(1).setTexture(texture);
                this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(1).setVisible(true);
            }
        }
        this.cancelSelectBorder();
        this.clearEquipInfo();
    },
    refreshSkill: function(roleId){
        for(var i=1;i<=8;i++){
            var characterSkills = Game.gameRecord[Game.currRecord]["character_skill"][roleId];
            //  设置技能图片
            var skillIsActive=false;
            if(characterSkills[i][1]>0){
                skillIsActive=true;
            }else{
                skillIsActive=false;
            }
            var imgPath = this.getSkillImgPathById(Game.characterBaseAttrInfo[roleId]["skill"][i],skillIsActive);
            var texture = cc.TextureCache.getInstance().addImage(imgPath);
            this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).setVisible(true);
            this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).setTexture(texture);
            // 设置技能星级
            var skillLevel = characterSkills[i][0];
            var levelTexturePath = "extra/stars_"+skillLevel+"_3.png";
            var levelTexture = cc.TextureCache.getInstance().addImage(levelTexturePath);
            this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getChildByTag(1).setTexture(levelTexture);
        }
    },
    // 根据type和id获得物品路径
    getEquipImgPathByTypeAndId: function(type,id){
        var equipImgPath="equips/";
        switch(type){
            case 1:
                equipImgPath=equipImgPath+"weapon/"+id+".png";
                break;
            case 2:
                equipImgPath=equipImgPath+"head/"+id+".png";
                break;
            case 3:
                equipImgPath=equipImgPath+"armor/"+id+".png";
                break;
            case 4:
                equipImgPath=equipImgPath+"hand/"+id+".png";
                break;
            case 5:
                equipImgPath=equipImgPath+"boots/"+id+".png";
                break;
            case 6:
                equipImgPath=equipImgPath+"ring/"+id+".png";
                break;
        }
        return equipImgPath;
    },
    // 根据id获取图片路径
    getSkillImgPathById:function(id, isActive){
        if(isActive){
            return "skills/"+id+".png";
        }else{
            return "skills/"+id+"_1.png";
        }
    },
    switchToBagTab: function(){
        this.ccbNode.getChildByTag(30).getChildByTag(3).setVisible(true);
        this.ccbNode.getChildByTag(30).getChildByTag(4).setVisible(false);
        this.currTab=0;
        var activeTexture = cc.TextureCache.getInstance().addImage("ccb/ccbResources/tab_active.png");
        var unactiveTexture = cc.TextureCache.getInstance().addImage("ccb/ccbResources/tab_unactive.png");
        this.ccbNode.getChildByTag(30).getChildByTag(1).setTexture(activeTexture);
        this.ccbNode.getChildByTag(30).getChildByTag(2).setTexture(unactiveTexture);
    },
    switchToSkillTab: function(){
        this.ccbNode.getChildByTag(30).getChildByTag(3).setVisible(false);
        this.ccbNode.getChildByTag(30).getChildByTag(4).setVisible(true);
        this.currTab=1;
        var activeTexture = cc.TextureCache.getInstance().addImage("ccb/ccbResources/tab_active.png");
        var unactiveTexture = cc.TextureCache.getInstance().addImage("ccb/ccbResources/tab_unactive.png");
        this.ccbNode.getChildByTag(30).getChildByTag(1).setTexture(unactiveTexture);
        this.ccbNode.getChildByTag(30).getChildByTag(2).setTexture(activeTexture);
    },
    switchRole: function(roleId){
        // 刷新技能配置情况
        this.refreshSkill(roleId);
        // 人物头像
        var characterTexture=cc.TextureCache.getInstance().addImage("character/"+roleId+".png");
        this.ccbNode.getChildByTag(20).getChildByTag(1).setTexture(characterTexture);
        // 人物的装备
        var characterInfo=Game.gameRecord[Game.currRecord]["character"];
        if(characterInfo[roleId][1]>0){
            var weaponTextureImg=this.getEquipImgPathByTypeAndId(1,characterInfo[roleId][1]);
            var weaponTexture=cc.TextureCache.getInstance().addImage(weaponTextureImg);
            this.ccbNode.getChildByTag(20).getChildByTag(11).getChildByTag(1).setTexture(weaponTexture);
            this.ccbNode.getChildByTag(20).getChildByTag(11).getChildByTag(1).setVisible(true);
        }else{
            this.ccbNode.getChildByTag(20).getChildByTag(11).getChildByTag(1).setVisible(false);
        }

        if(characterInfo[roleId][2]>0){
            var headTextureImg=this.getEquipImgPathByTypeAndId(2,characterInfo[roleId][2]);
            var headTexture=cc.TextureCache.getInstance().addImage(headTextureImg);
            this.ccbNode.getChildByTag(20).getChildByTag(12).getChildByTag(1).setTexture(headTexture);
            this.ccbNode.getChildByTag(20).getChildByTag(12).getChildByTag(1).setVisible(true);
        }else{
            this.ccbNode.getChildByTag(20).getChildByTag(12).getChildByTag(1).setVisible(false);
        }

        if(characterInfo[roleId][3]>0){
            var armorTextureImg=this.getEquipImgPathByTypeAndId(3,characterInfo[roleId][3]);
            var armorTexture=cc.TextureCache.getInstance().addImage(armorTextureImg);
            this.ccbNode.getChildByTag(20).getChildByTag(13).getChildByTag(1).setTexture(armorTexture);
            this.ccbNode.getChildByTag(20).getChildByTag(13).getChildByTag(1).setVisible(true);
        }else{
            this.ccbNode.getChildByTag(20).getChildByTag(13).getChildByTag(1).setVisible(false);
        }

        if(characterInfo[roleId][4]>0){
            var bootsTextureImg=this.getEquipImgPathByTypeAndId(4,characterInfo[roleId][4]);
            var bootsTexture=cc.TextureCache.getInstance().addImage(bootsTextureImg);
            this.ccbNode.getChildByTag(20).getChildByTag(14).getChildByTag(1).setTexture(bootsTexture);
            this.ccbNode.getChildByTag(20).getChildByTag(14).getChildByTag(1).setVisible(true);
        }else{
            this.ccbNode.getChildByTag(20).getChildByTag(14).getChildByTag(1).setVisible(false);
        }
        
        if(characterInfo[roleId][5]>0){
            var handTextureImg=this.getEquipImgPathByTypeAndId(5,characterInfo[roleId][5]);
            var handTexture=cc.TextureCache.getInstance().addImage(handTextureImg);
            this.ccbNode.getChildByTag(20).getChildByTag(15).getChildByTag(1).setTexture(handTexture);
            this.ccbNode.getChildByTag(20).getChildByTag(15).getChildByTag(1).setVisible(true);
        }else{
            this.ccbNode.getChildByTag(20).getChildByTag(15).getChildByTag(1).setVisible(false);
        }
        
        if(characterInfo[roleId][6]>0){
            var ringTextureImg=this.getEquipImgPathByTypeAndId(6,characterInfo[roleId][6]);
            var ringTexture=cc.TextureCache.getInstance().addImage(ringTextureImg);
            this.ccbNode.getChildByTag(20).getChildByTag(16).getChildByTag(1).setTexture(ringTexture); 
            this.ccbNode.getChildByTag(20).getChildByTag(16).getChildByTag(1).setVisible(true);
        }else{
            this.ccbNode.getChildByTag(20).getChildByTag(16).getChildByTag(1).setVisible(false);
        }
        this.cancelSelectBorder();
        this.clearEquipInfo();     
    },
    setEquipInfo: function(type,id){
        if(type==0 && id==0){
            this.clearEquipInfo();
        }else{
            this.itemNameLabel.setString(Game.equipInfo[type][id]["name"]);
            this.itemInfoLabel.setString(Game.equipInfo[type][id]["intro"]);
            this.itemAttrLabel.setString(Game.equipInfo[type][id]["attr"]);
            this.itemNameLabel.setVisible(true);
            this.itemInfoLabel.setVisible(true);
            this.itemAttrLabel.setVisible(true);
            this.skillActiveBtn.setVisible(false);
        }
    },
    clearEquipInfo: function(){
        this.itemNameLabel.setVisible(false);
        this.itemInfoLabel.setVisible(false);     
        this.itemAttrLabel.setVisible(false);
        this.skillActiveBtn.setVisible(false);
    },
    setSkillInfo: function(id, isActive){
        if(id==0){
            this.clearSkillInfo();
        }else{
            var texture=null;
            if(isActive==1){
                texture=cc.TextureCache.getInstance().addImage("ccb/ccbResources/skill_switch_active.png");
            }else{
                texture=cc.TextureCache.getInstance().addImage("ccb/ccbResources/skill_switch_inactive.png");
            }
            this.skillActiveBtn.setTexture(texture);
            this.itemNameLabel.setString(Game.skillData[id]["name"]);
            this.itemInfoLabel.setString(Game.skillData[id]["intro"]);
            this.itemAttrLabel.setString("");
            this.itemNameLabel.setVisible(true);
            this.itemInfoLabel.setVisible(true);
            this.itemAttrLabel.setVisible(true);
            this.skillActiveBtn.setVisible(true);
        }
    },
    clearSkillInfo: function(){
        this.itemNameLabel.setVisible(false);
        this.itemInfoLabel.setVisible(false);     
        this.itemAttrLabel.setVisible(false);
        this.skillActiveBtn.setVisible(false);
        this.touchedSkillSelectedId=0;
    },
    showItemSelectBorder: function(type,index){
        if(type==1){
            // 是背包
            for(var i=1;i<=6;i++){
                // this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setVisible(false);
                // this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setOpacity(0);
            }
            for(var i=1;i<=20;i++){
                if(index==i){
                    this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setVisible(true);
                    this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setOpacity(255);
                }else{
                    this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setVisible(false);
                    this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setOpacity(0);
                }
            }
        }
        if(type==2){
            // 是角色面板
            for(var i=1;i<=20;i++){
                this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setVisible(false);
                this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setOpacity(0);
            }
            for(var i=1;i<=6;i++){
                // if(index==i){
                //     this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setVisible(true);
                //     this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setOpacity(255);
                // }else{
                //     this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setVisible(false);
                //     this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setOpacity(0);
                // }
            }
        }
    },
    showSkillSelectBorder: function(index){
        for(var i=1;i<=8;i++){
                if(index==i){
                    this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getChildByTag(2).setVisible(true);
                    this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getChildByTag(2).setOpacity(255);
                }else{
                    this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getChildByTag(2).setVisible(false);
                    this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getChildByTag(2).setOpacity(0);
                }
            }
    },
    cancelSelectBorder: function(){
        for(var i=1;i<=20;i++){
            this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setVisible(false);
            this.ccbNode.getChildByTag(30).getChildByTag(3).getChildByTag(i).getChildByTag(2).setOpacity(0);
        }
        for(var i=1;i<=6;i++){
            // this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setVisible(false);
            // this.ccbNode.getChildByTag(20).getChildByTag(i).getChildByTag(2).setOpacity(0);
        }
        for(var i=1;i<=8;i++){
            this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getChildByTag(2).setVisible(false);
            this.ccbNode.getChildByTag(30).getChildByTag(4).getChildByTag(1).getChildByTag(i).getChildByTag(2).setOpacity(0);
        }
        this.clearSkillInfo();
        this.clearEquipInfo();
    }
});

var EquipSkillScene = cc.Scene.extend({
    onEnter:function () {
        this._super();
        var layer = new EquipSkillLayer();
        layer.init();
        this.addChild(layer);
    }
});